{% extends "base.html" %}
{% load i18n %}
{% load account socialaccount %}
{% load static %}

{% block title %}登录{% endblock %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8 col-lg-6">
            <div class="card shadow-sm mt-5">
                <div class="card-body p-5">
                    <h2 class="text-center mb-4">欢迎回来</h2>
                    
                    {% get_providers as socialaccount_providers %}
                    {% if socialaccount_providers %}
                        <!-- 第三方登录部分 -->
                        <div class="social-login mb-4">
                            <p class="text-center text-muted">使用社交账号登录</p>
                            <div class="d-flex justify-content-center gap-3 mb-4">
                                {% include "socialaccount/snippets/provider_list.html" with process="login" %}
                            </div>
                            <div class="divider">
                                <span class="divider-text">或</span>
                            </div>
                        </div>
                    {% endif %}

                    <!-- 本地登录表单 -->
                    <form class="login" id="login_form" method="POST" action=".">
                        {% csrf_token %}
                        <div class="form-group mb-3">
                            <label for="id_login" class="form-label">账号</label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="fas fa-user"></i></span>
                                <input type="text" name="login" placeholder="用户名或Email" 
                                       class="form-control" id="id_login" required />
                            </div>
                        </div>

                        <div class="form-group mb-3">
                            <label for="id_password" class="form-label">密码</label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="fas fa-lock"></i></span>
                                <input type="password" name="password" placeholder="请输入密码" 
                                       class="form-control" id="id_password" required />
                            </div>
                        </div>

                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <div class="form-check">
                                <input type="checkbox" name="remember" id="id_remember" 
                                       class="form-check-input" checked />
                                <label class="form-check-label" for="id_remember">
                                    保持登录
                                </label>
                            </div>
                            <a href="{% url 'password_reset' %}" class="text-primary">
                                忘记密码?
                            </a>
                        </div>

                        <button type="submit" class="btn btn-primary w-100 mb-3">
                            登录
                        </button>

                        <p class="text-center mb-0">
                            还没有账号？
                            <a href="{% url 'userprofile:register' %}" class="text-primary">
                                注册新账号
                            </a>
                        </p>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
/* 登录卡片样式 */
.card {
    border: none;
    border-radius: 15px;
}

/* 分隔线样式 */
.divider {
    position: relative;
    text-align: center;
    margin: 20px 0;
}

.divider::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    height: 1px;
    background: #e0e0e0;
}

.divider-text {
    background: #fff;
    padding: 0 15px;
    color: #6c757d;
    position: relative;
    font-size: 14px;
}

/* 社交登录按钮样式 */
.socialaccount_providers {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    gap: 15px;
    justify-content: center;
}

.socialaccount_provider {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.3s ease;
    font-weight: 500;
}

/* GitHub 按钮样式 */
.socialaccount_provider.github {
    background-color: #24292e;
    color: white;
}

.socialaccount_provider.github:hover {
    background-color: #1b1f23;
    text-decoration: none;
    color: white;
}

/* Google 按钮样式 */
.socialaccount_provider.google {
    background-color: #fff;
    color: #757575;
    border: 1px solid #ddd;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.socialaccount_provider.google:hover {
    background-color: #f8f9fa;
    text-decoration: none;
}

/* 输入框样式 */
.form-control {
    border-radius: 8px;
    padding: 10px 15px;
}

.input-group-text {
    background-color: transparent;
    border-right: none;
}

.form-control:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

/* 按钮样式 */
.btn-primary {
    padding: 10px;
    border-radius: 8px;
    font-weight: 500;
}

/* 响应式调整 */
@media (max-width: 576px) {
    .card-body {
        padding: 2rem !important;
    }
}
</style>
{% endblock %}